/* main.cpp */
#include <cstdio>
#include <iostream>
#include <windows.h>

// win64
//#pragma comment(lib,"..\\..\\bin\\libcellexD.lib")

// 用户唯一需要包含的头文件
#include "..\include\libcellex.h"

int print_line() { for (int i = 0; i < 40; i++) printf("-"); printf("\n"); return 0; };
int test_load();
int test_include(int c, int d);
int test_func2(int* pa);
int test3(int* pa);
int test4(off_info** p);

int test4(off_info** p)
{
	return 0;
}

int main(int argc, char* argv[])
{
	printf("this is test for libcellex.\n");

	//off_info* p1(nullptr);
	off_info* p1;
	libcellex_init(&p1);


	if (nullptr == argv[1])
	{
		std::cout << "please input a file like: main.exe xx.off" << std::endl;
		return -1;
	}
	//char file1[] = "t3.off";

	read_off(argv[1]);

	std::cout << "\nvertices: " << p1->vertices
		<< ", faces:" << p1->faces << ", edges:" << p1->edges << std::endl;

	for (int i = 0; i < p1->vertices; i++)
	{
		//	auto v2 = p1->v_info[i]  编译报错
		auto v2 = &p1->v_info[i];

		std::cout << "vid: " << v2->id << ", x:" << v2->point[0] << ", y:" << v2->point[1] << ", z:" << v2->point[2] << "\n";
	}

	// face
	for (int i = 0; i < p1->faces; i++)
	{
		// face index
		auto pf = &p1->f_info[i];

		//std::cout << "fid:" << pf->id;
		std::cout << "v_size:" << pf->vertice_size;

		for (auto j = 0; j < pf->vertice_size; j++)
		{
			std::cout << ", index: " << pf->vertice_index[j];
		}
		std::cout << std::endl;
	}
	/* << "vertice point x:" << p1->vertices_list[0] << std::endl
			<< "vertice index 0列:" << p1->f_info[0].vertice_index[1] << std::endl;
	*/
	//Sleep(1000);
	int n1(0);

	libcellex_free(p1);

	int n(0);
	return 0;
}

int test3(int* pa)
{
	func3_pointer(pa, 4, 4);

	std::cout << "pa[1][0] = " << pa[0 + 4] << std::endl;
	return 0;
}

int test_func2(int* pa)
{
	func2_pointer(pa, 0);
	std::cout << "pa[0] = " << pa[0] << std::endl;
	return 0;
}

int test_load()
{

#ifdef _DEBUG
	char szdll[] = "libcellexD.dll";
#else
	char szdll[] = "libcellex.dll";
#endif

	//HINSTANCE hDll = LoadLibraryA("libcellexD.dll");
	HINSTANCE hDll = LoadLibraryA(szdll);

	if (!hDll)
	{
		std::cout << "error" << std::endl;
		return -1;
	}

	typedef int (*PFN_ADD)(int a, int b);

	// bug pfn is null
	FARPROC pfn = GetProcAddress(hDll, "m_pr");
	if (nullptr == pfn)
	{
		std::cout << "error2" << std::endl;
	}
	else
	{
		((PFN_ADD)pfn)(1, 3);
	}

	FreeLibrary(hDll);
	return 0;
}

int test_include(int c, int d)
{
	return m_pr(c, d);
}

